package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.common.constant.RedisConstant;
import com.atguigu.lease.model.entity.ApartmentInfo;
import com.atguigu.lease.web.app.mapper.ApartmentInfoMapper;
import com.atguigu.lease.web.app.service.ApartmentInfoService;
import com.atguigu.lease.web.app.vo.apartment.ApartmentDetailVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @author xiongkunYang
 * @description 针对表【apartment_info(公寓信息表)】的数据库操作Service实现
 * @createDate 2025-04-19 22:27:34
 */
@Service
@RequiredArgsConstructor
public class ApartmentInfoServiceImpl extends ServiceImpl<ApartmentInfoMapper, ApartmentInfo>
        implements ApartmentInfoService {

    private final ApartmentInfoMapper apartmentInfoMapper;
    private final RedisTemplate<String, Object> redisTemplate;

    @Override
    public ApartmentDetailVo getDetailVoById(Long id) {
        String key = RedisConstant.APP_APARTMENT_PREFIX + id;
        ApartmentDetailVo apartmentDetailVo = (ApartmentDetailVo) this.redisTemplate.opsForValue().get(key);
        if (apartmentDetailVo == null) {
            apartmentDetailVo = this.apartmentInfoMapper.selectDetailVoById(id);
            this.redisTemplate.opsForValue().set(key, apartmentDetailVo);
        }
        return apartmentDetailVo;
//        return this.apartmentInfoMapper.selectDetailVoById(id);
    }
}




